/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conversorcsvxml;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Marcel
 */
public class LeitorTXT {
    
    public Construtor construtor;
    
    public LeitorTXT (Construtor construtor) {
        this.construtor = construtor;
    }
    
    public void converter (String arquivo) {
        InputStream input = null;
        try  {
            input = new FileInputStream (arquivo);
            Scanner in = new Scanner (input);
            construtor.construirDocumento("notas");
            while (in.hasNext()) {
                construtor.construirLinha(5);
                int matricula = in.nextInt();
                construtor.construirCelula("matricula", matricula + "");
                float p1 = in.nextFloat();
                construtor.construirCelula("p1", p1 + "");
                float p2 = in.nextFloat();
                construtor.construirCelula("p2", p2 + "");
                float media = (p1 + p2) / 2;
                float vs = 0;
                if (media >= 4&& media <= 6) {
                    vs = in.nextFloat();
                }
                construtor.construirCelula("vs", vs + "");
                String nome = in.nextLine();
                construtor.construirCelula("nome", nome);
            }
        }
        catch (FileNotFoundException ex) {
            
        }
        catch (IOException io) {
            
        }
        finally {
            try {
                input.close();
            } catch (IOException ex) {
                Logger.getLogger(LeitorTXT.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
}
